package com.metagurukul.metaspace.service;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.metagurukul.metaspace.dao.CommentDao;
import com.metagurukul.metaspace.dao.StatusDao;
import com.metagurukul.metaspace.dao.UserPersonalDetailDao;
import com.metagurukul.metaspace.models.beans.Comment;
import com.metagurukul.metaspace.models.beans.CommentUserDetail;
import com.metagurukul.metaspace.models.beans.Status;
import com.metagurukul.metaspace.models.beans.StatusUserDetail;
import com.metagurukul.metaspace.models.beans.UserPersonalDetail;

public class StatusCommentService {
	private StatusCommentService(){
		
	}

	public static int deleteComment(int commentId) throws SQLException {
		CommentDao dao = new CommentDao();
		return dao.deleteRecord(commentId);
	}

	public static int insertComment(Comment comment) throws SQLException {
		CommentDao dao = new CommentDao();
		return dao.addRecord(comment);
	}

	public static int deleteStatus(int statusId) throws SQLException {
		StatusDao dao = new StatusDao();
		return dao.deleteRecord(statusId);
	}

	public static int addStatus(Status status) throws SQLException {
		StatusDao dao = new StatusDao();
		return dao.addRecord(status);
	}
	
	 
	public static List<StatusUserDetail> getStatusList()
			throws SQLException {
		StatusDao dao = new StatusDao();
		List<Status> list = new ArrayList<Status>();
		list = dao.getRecordList();
		List<StatusUserDetail> statusUserList = new ArrayList<StatusUserDetail>();
		for(int i=0; i<list.size();i++){
			int userId = list.get(i).getUserId();
			UserPersonalDetailDao userDao = new UserPersonalDetailDao();
			UserPersonalDetail userPersonalDetail = userDao.getRecord(userId);
			StatusUserDetail statusUserDetail = new StatusUserDetail();
			statusUserDetail.setGender(userPersonalDetail.getGender());
			statusUserDetail.setName(userPersonalDetail.getName());
			statusUserDetail.setProfilePicName(userPersonalDetail.getProfilePicPath());
			statusUserDetail.setStatus(list.get(i).getStatus());
			statusUserDetail.setStatusId(list.get(i).getStatusId());
			statusUserDetail.setStatusTimestamp(list.get(i).getStatusTimestamp());
			statusUserDetail.setUserId(userId);
			statusUserList.add(statusUserDetail);
		}
		return statusUserList;

	}

	public static List<Status> getStatusListByUserId(int userId)
			throws SQLException {
		StatusDao dao = new StatusDao();
		return dao.getRecordListByUserId(userId);
		

	}

	public static List<CommentUserDetail> getCommentList(int statusId)
			throws SQLException {
		CommentDao dao = new CommentDao();
		List<Comment> list = new ArrayList<Comment>();
		list = dao.getRecordList(statusId);
		List<CommentUserDetail> commentUserList = new ArrayList<CommentUserDetail>();
		for(int i=0; i<list.size();i++){
			int userId = list.get(i).getUserId();
			UserPersonalDetailDao userDao = new UserPersonalDetailDao();
			UserPersonalDetail userPersonalDetail = userDao.getRecord(userId);
			CommentUserDetail commentUserDetail = new CommentUserDetail();
			commentUserDetail.setGender(userPersonalDetail.getGender());
			commentUserDetail.setName(userPersonalDetail.getName());
			commentUserDetail.setProfilePicName(userPersonalDetail.getProfilePicPath());
			commentUserDetail.setComment(list.get(i).getComment());
			commentUserDetail.setCommentId(list.get(i).getCommentId());
			commentUserDetail.setStatusId(list.get(i).getStatusId());
			commentUserDetail.setCommentTimestamp(list.get(i).getCommentTimestamp());
			commentUserDetail.setUserId(userId);
			commentUserList.add(commentUserDetail);
		}
		return commentUserList;

	}

	
	
}
